home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c
- Path: nntp.coast.net!torn!sq!msb
- From: msb@sq.com (Mark Brader)
- Subject: Re: Restrictions on qsort compare function?
- Message-ID: <1996Mar22.204023.10235@sq.com>
- Organization: SoftQuad Inc., Toronto, Canada
- References: <4iokop$h4p@lyra.csx.cam.ac.uk> <1996Mar21.113301.2622@sq.com> <4it51b$ng8@usenet.pa.dec.com> <4iukhc$5nr@rdsunx.crd.ge.com>
- Date: Fri, 22 Mar 1996 20:40:23 GMT
-
- > Alternatively, how about this:
- >
- > return ((signed int) ((unsigned int)a - (unsigned int)b));
-
- Assuming that a and b are int, this line cannot produce undefined
- behavior, but if a < b, the value returned is implementation-defined
- and in particular its sign is not specified by the standard.
-
- If the implementation allows this returned value to be non-negative
- for some values of a and b, then the function is not a legitimate
- comparison function for qsort() because it may not be transitive.
- Therefore the code is not strictly conforming.
- --
- Mark Brader, msb@sq.com "do right; have fun; make money"
- SoftQuad Inc., Toronto -- Ian Darwin on Yuri Rubinsky (1952-96)
-
- My text in this article is in the public domain.
-